/**
 * parseImagePopups() parses the page for links to images that are set to open in a new window,
 * and changes them to open in a special popup
*/
function parseImagePopups() {

	// Parse all <a> tags
	var link_elements = document.getElementById("mainbody").getElementsByTagName("a");

	// For each link
	for (var i = 0; i < link_elements.length; i++) {

		// Reference
		var link_obj = link_elements.item(i);

		// If it links to an image, and is a popup
		if (link_obj.href.indexOf(".jpg") != -1 && link_obj.target == "_blank") {

			// Update URL
			link_obj.href = "javascript:popupImage('" + link_obj.href + "');";
			link_obj.target = "_self";
		}
	}
}

/**
*saveTags()
*
*/
function saveTags(tags,blog_id){
	
	var check = document.getElementById(tags).checked;
	
	var xmlhttp1;
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp1=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp1.onreadystatechange=function()
	{
	  	if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
		{
			var feedback=xmlhttp1.responseText;
			document.getElementById('div_notice').innerHTML = "&nbsp;&nbsp;"+feedback;	
			//alert(feedback);
		}
	}
	
	xmlhttp1.open("GET","../site_specific/getHelpCredit.php?flag="+check+"&tag="+tags+"&blog="+blog_id,true);
	xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlhttp1.send();
}

function addTags(page_id){
	
	var text = document.getElementById('new_tag').value;
	
	document.getElementById('div_notice').innerHTML = '';
	
	var xmlhttp1;
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp1=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
	}
  
	xmlhttp1.onreadystatechange=function()
	{
	  	if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
		{
			var feedback=xmlhttp1.responseText;	
			
			var array_feedback = feedback.split('%%%###');
			
			document.getElementById('div_selected_tags').innerHTML = array_feedback[0];
			
			var option_lists = array_feedback[1].split('@@@!!!');
			
			var select_element = document.getElementById('select_delete_tag');
			
			var select_length = select_element.length;
			
			for(var i=0;i<select_length;i++){
				document.getElementById('select_delete_tag').remove(0);
			}
			
			
						
			for(index in option_lists){

				select_element.options[select_element.options.length] = new Option(option_lists[index],option_lists[index]);
			}
		}
	}
	
	xmlhttp1.open("GET","../site_specific/addTags.php?text="+text+"&id="+page_id,true);
	xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlhttp1.send();
}

function deleteTags(page_id){
	
	var value = document.getElementById("select_delete_tag").value;
	
	document.getElementById('div_notice').innerHTML = '';
	
	var xmlhttp1;
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp1=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
	}
  
	xmlhttp1.onreadystatechange=function()
	{
	  	if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
		{
			var feedback=xmlhttp1.responseText;	
			//alert(feedback);
			var array_feedback = feedback.split('%%%###');
			
			document.getElementById('div_selected_tags').innerHTML = array_feedback[0];
			
			var option_lists = array_feedback[1].split('@@@!!!');
			
			var select_element = document.getElementById('select_delete_tag');
			
			var select_length = select_element.length;
			
			for(var i=0;i<select_length;i++){
				document.getElementById('select_delete_tag').remove(0);
			}
						
			for(index in option_lists){

				select_element.options[select_element.options.length] = new Option(option_lists[index],option_lists[index]);
			}
		}
	}
	
	xmlhttp1.open("GET","../site_specific/deleteTags.php?value="+value+"&id="+page_id,true);
	xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlhttp1.send();
}

/**
 * deleteUploadedFile() submits a form to delete an uploaded file
*/
function deleteUploadedFile(file_name) {

	//Confirm choice
	if (confirm("Are you sure you wish to delete this file? This action cannot be undone.")) {

		// Set hidden var
		document.getElementById("deletefile").value = file_name;

		// Submit form
		document.getElementById("deletefileform").submit();
	}
}

function ShowPics(id){
	
	document.getElementById('display_img').src = '../front/gallery/'+id;
	//document.getElementById(id).style.color = '#0101DF';
	
	var length = document.getElementById('admin_table').getElementsByTagName('a').length;
	
	var object = document.getElementById('admin_table').getElementsByTagName('a');
	
	for(var i=0;i<length;i++){
		
		if(object.item(i).id !=id){

			object.item(i).style.color= '#5FB404';
		}
		else{
			
			object.item(i).style.color= '#FF00FF';
		}
	}
	
}